package com.mindbook.vip.gawxchatinfo.controller.home;

import com.mindbook.vip.gawxchatinfo.entity.home.FirstPageInfoDetails;
import com.mindbook.vip.gawxchatinfo.service.home.FirstPageInfoDetailsService;
import com.mindbook.vip.gawxchatinfo.utils.crud.CrudUtils;
import com.mindbook.vip.gawxchatinfo.utils.result.Result;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultEnum;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @NAME: wxb
 * @DATE: 2022/5/16
 * @DESCRIPTION: 首页标题下的内容
 **/
@RestController
@RequestMapping("firstPageInfoDetails")
@Api(value = "首页标题内容")
public class FirstPageInfoDetailsController {

    @Autowired private FirstPageInfoDetailsService firstPageInfoDetailsService;


    @ApiOperation(value = "新增")
    @PostMapping("/")
    public Result add(FirstPageInfoDetails firstPageInfoDetails){

        Integer add = firstPageInfoDetailsService.add(firstPageInfoDetails);

        CrudUtils.validateAddResult(add);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_ADD_SUCCESS.getMsg());
    }
    
    @ApiOperation(value="修改")
    @PutMapping("/")
    public Result update(FirstPageInfoDetails firstPageInfoDetails){

        Integer put = firstPageInfoDetailsService.put(firstPageInfoDetails);

        CrudUtils.validateAddResult(put);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_UPDATE_SUCCESS.getMsg());
    }



    @ApiOperation(value = "删除")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        Integer integer = firstPageInfoDetailsService.removeByPrimaryKey(id);

        CrudUtils.validateDeleteResult(integer);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_DELETE_SUCCESS.getMsg());
    }

    @ApiOperation(value="根据title的id 查询列表")
    @GetMapping("/title/{id}")
    public Result getByTitleId(@PathVariable Integer id){
        List<FirstPageInfoDetails> listByTitleId = firstPageInfoDetailsService.findListByTitleId(id);
        return ResultUtils.genSuccessResult(listByTitleId);
    }

}
